<?php
$this->headTitle('Danh mục BĐS','append');
?>
<div class="dashboard-menu dashboard-admin">
    <span class="back">&nbsp;</span>
    <a href="/admin/role"><h1>Bất động sản</h1></a>
    <span class="text">Demo</span>
</div>
<div class="row placeholders">
    <div class="col-md-12">
        <div class="widget-big">
            <div class="search-result text-left">
                <?php                    
                    if(isset($this->mess)){
                        if($this->flag == 'success')
                            echo '<div class="bg-success">',$this->mess,'</div>';
                        elseif($this->flag == 'alert')
                            echo '<div class="bg-warning">',$this->mess,'</div>';
                        else
                            echo '<div class="bg-danger">',$this->mess,'</div>';
                    }
                ?>
                <form id="form" class="form-option" method="post" action="" enctype="multipart/form-data" name="form">
                    <dl class="zend_form">                        
                       
                        <dt><label>Hình thức giao dịch</label></dt>
                        <dd>
                            <select id="transaction" name="transaction">
                                <option value="-1">--- Chọn hình thức giao dịch ---</option>
                                <option value="rent">Thuê</option>
                                <option value="sale">Bán</option>
                            </select>                            
                        </dd>
                        
                        <dt><label>Bất động sản</label></dt>
                        <dd>
                            <select id="estate" name="estate">
                                <option value="-1">--- Chọn loại bất động sản ---</option>                                
                            </select>                            
                        </dd>
                        
                        <dt id="otherInfo"><label>Thông tin khác</label></dt>
                        <dd id="otherInfo">
                            <div class="option-wrapper">
                                <div class="fieldset">
                                    <div class="legend"></div>
                                    <div class="fieldset-content">
                                    <ul>
                                        <li><label>Mặt tiền</label><input type='text' class='resourceIdAdmin' name='facede' value=''/></li>                                                                                                            
                                        <li><label>Đường vào</label><input type='text' class='resourceIdAdmin' name='entranceWidth' value=''/></li>
                                        <li><label>Rộng</label><input type='text' class='resourceIdAdmin' name='width' value=''/></li>
                                        <li><label>Dài</label><input type='text' class='resourceIdAdmin' name='length' value=''/></li>
                                        <li><label>Hướng nhà</label><select name="car"><option>Đông</option></select></li>
                                        <li><label>Hướng ban công</label><select name="balCar"><option>Đông</option></select></li>
                                        <li><label>Số tầng</label><input type='text' class='resourceIdAdmin' name='numFloor' value=''/></li>
                                        <li><label>Lầu</label><input type='text' class='resourceIdAdmin' name='floor' value=''/></li>
                                        <li><label>Số toilet</label><input type='text' class='resourceIdAdmin' name='toilet' value=''/></li>
                                        <li><label>Số phòng ngủ</label><input type='text' class='resourceIdAdmin' name='bedroom' value=''/></li>
                                    <div class="clearfix"></div>
                                    </ul>
                                    </div>
                                </div>
                            </div>
                        </dd>
                        
                        <dt id="baseUtility"><label>Tiện ích cơ bản</label></dt>
                        <dd id="baseUtility">
                            <div class="option-wrapper">
                                <div class="fieldset">
                                    <div class="legend"></div>
                                    <div class="fieldset-content">
                                    <ul>
                                    <?php 
                                        foreach ($this->otherInfo as $info){
                                            if($info['groupInfo'] == 'baseUtility'){
                                                echo "<li><label>{$info['name']}</label><input type='text' class='resourceIdAdmin' name='resourceId[]' value='{$info['id']}'></li>";
                                            }
                                        }
                                    ?>                                                                        
                                    <div class="clearfix"></div>
                                    </ul>
                                    </div>
                                </div>
                            </div>
                        </dd>
                        
                        <dt id="otherUtility"><label>Tiện ích khác</label></dt>
                        <dd id="otherUtility">
                            <div class="option-wrapper">
                                <div class="fieldset">
                                    <div class="legend"><input type="checkbox" name="otherUtility" id="check_all_resource_default"/><label>Chọn</label></div>
                                    <div class="fieldset-content">
                                    <ul>
                                    <?php 
                                        foreach ($this->otherInfo as $info){
                                            if($info['groupInfo'] == 'otherUtility'){
                                                echo "<li><input type='checkbox' class='resourceIdAdmin' name='resourceId[]' value='{$info['id']}'><label>{$info['name']}</label></li>";
                                            }
                                        }
                                    ?>                                                                        
                                    <div class="clearfix"></div>
                                    </ul>
                                    </div>
                                </div>
                            </div>
                        </dd>                                                                                           
                        
                        <dd id="submit-element">
                            <input value="Thêm mới" class="button" type="submit" />
                            <input value="Reset" class="button" type="reset"/>
                        </dd>
                    </dl>
                </form>
            </div>
        </div>
    </div>
</div>

<script>
    $(document).ready(function(){
        $('select#transaction').change(function(){
            var tran=$(this).val();                                                
            $.ajax({
                type: "POST",
                url: "/admin/estate/getestate/transaction/"+tran,                                    
                //data: id_dm1,                
                dataType: 'json',                
                success: function(data) {
                    //alert(JSON.stringify(data));
                    $('select#estate option[value!="-1"]').remove();
                    //$('select#estate').append(new Option('--- Chọn loại bất động sản ---','0'));
                    for(var key in data)
                    {                        
                        $('select#estate').append(new Option(data[key],key));
                    }                    
                    //alert("AJAX call successful and this data was returned: " + data);                    
                },
                error: function() {
                    alert('failed');
                    $('select#danhmuc2 option[value!="-1"]').remove();
                }
            });
            return false;                       
        });
    });
    $(document).ready(function(){
        $('select#estate').change(function(){
            var estate=$(this).val();                                                            
            $.ajax({
                type: "POST",
                url: "/admin/estate/getutility/estate/"+estate,                                    
                //data: id_dm1,                
                dataType: 'json',                
                success: function(data) {                    
                    //alert(JSON.stringify(data));                                                            
                    for(var key in data){
                        if(key=='otherInfoShow'){
                            for(var key in data['otherInfoShow']){
                                 $('[name='+data['otherInfoShow'][key]+']').parent().attr('style','') ;                                                                 
                            }                                                        
                        }
                        if(key=='otherInfoHide'){
                            for(var key in data['otherInfoHide']){
                                 $('[name='+data['otherInfoHide'][key]+']').parent().attr('style','display: none') ;                                                                 
                            }                                                        
                        }
                        if(key=='baseUtility'){
                            if(data[key]=='0'){
                                $('dt#baseUtility').attr('style','display: none');    
                                $('dd#baseUtility').attr('style','display: none');    
                            }else{
                                $('dt#baseUtility').attr('style','');    
                                $('dd#baseUtility').attr('style','');
                            }                            
                        }
                        if(key=='otherUtility'){
                            if(data[key]=='0'){
                                $('dt#otherUtility').attr('style','display: none');    
                                $('dd#otherUtility').attr('style','display: none');    
                            }else{
                                $('dt#otherUtility').attr('style','');    
                                $('dd#otherUtility').attr('style','');
                            }                            
                        }
                        
                    } 
                    //alert("AJAX call successful and this data was returned: " + data);                    
                },
                error: function() {
                    //alert('failed');
                    //$('select#danhmuc2 option[value!="-1"]').remove();
                }
            });
            return false;                       
        });
    });       
</script>